package com.example.jyjava.controller;

import com.alibaba.fastjson.JSON;
import com.example.jyjava.bean.Feedback;
import com.example.jyjava.dao.FeedbackDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackDao feedbackDao;

    @RequestMapping("/addFeebdack")
    public String addFeedback(@RequestBody Feedback feedback){
        String falg = "400";
        feedback.setCreatTime(new Date());
        feedback.setDeleteType(false);
        int i = feedbackDao.addFeedback(feedback);
        HashMap<String, Object> res = new HashMap<>();
        if (i > 0){
            falg = "200";
            res.put("flag",falg);
            res.put("feedback",i);
        }else{
            res.put("flag",falg);
        }
        String s = JSON.toJSONString(res);
        return s;
    }
}
